package com.atguigu.stgy.admin.service.impl;

import com.atguigu.stgy.admin.service.ApartmentFeeValueService;
import com.atguigu.stgy.model.dto.ApartmentDTO;
import org.springframework.stereotype.Service;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.stgy.model.entity.ApartmentFeeValue;
import com.atguigu.stgy.admin.mapper.ApartmentFeeValueMapper;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class ApartmentFeeValueServiceImpl extends ServiceImpl<ApartmentFeeValueMapper, ApartmentFeeValue> implements ApartmentFeeValueService {

   public void bathSaveFeeValue(ApartmentDTO apartmentDTO, Long apartmentInfoId) {

       if (CollectionUtils.isEmpty(apartmentDTO.getFeeValueIds())){
           return ;
       }
        List<ApartmentFeeValue> feeValues = apartmentDTO.getFeeValueIds().stream().map(feeValueId -> {

            ApartmentFeeValue apartmentFeeValue = new ApartmentFeeValue();
            apartmentFeeValue.setApartmentId(apartmentInfoId);
            apartmentFeeValue.setFeeValueId(feeValueId);
            return apartmentFeeValue;

        }).collect(Collectors.toList());
        this.saveBatch(feeValues);
    }

}
